<?php
declare (strict_types=1);

namespace app\common\model\payment\admin;

use app\common\model\BaseModel;

/**
 * 订单模型
 */
class PaymentOrder extends BaseModel
{
    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'payment_order';

    protected $type = [
        'payment_time' => 'timestamp',
        'addrinfo'     => 'array'
    ];

    /**
     * 订单支付状态
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-04
     *
     * @param    [type]                         $value [description]
     * @param    [type]                         $data  [description]
     */
    public function getStatusTextAttr($value, $data): string
    {
        $text = $this->getStatusTextInfo();

        return $text[$data['status']] ?? '未知';
    }

    protected function getStatusTextInfo(): array
    {
        return [
            0  => '已取消',
            10 => '待支付',
            20 => '已付款',
            30 => '已申请退款,待确认',
            40 => '退款已确认,退款中',
            50 => '已退款',
            60 => '已失效',
            70 => '已支付,但被管理员移除',
            80 => '拼团已支付，未成团'
        ];
    }

    /**
     * 获取状态选项数据
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-04
     */
    public function getStatusOptions(): array
    {
        $options = [];

        $status = $this->getStatusTextInfo();
        foreach ($status as $key => $value) {
            $options[] = ['title' => $value, 'value' => $key];
        }

        return $options;
    }

}
